﻿namespace ExcelTool {
    using System;
    using System.Collections.Generic;
    using System.Text;
    using libxl;
    class Reporter {
        static public List<string> errList = new List<string>();
        static public string metalib = "Metalib";
        static public string set = "Set";
        static public string entry = "Entry";
        static private Dictionary<string, string> procRec = new Dictionary<string, string>();

        static public void SetMetalibProgress(string param) {
            procRec[metalib] = param;
        }
        static public void SetSetProgress(string param) {
            procRec[set] = param;
        }

        static public void SetEntryProgress(string param) {
            procRec[entry] = param;
        }

        static public void RecordConverterInfo(XmlBaseEntry fe) {
            procRec[entry] = fe.name;
            procRec[set] = fe.ParentSet.name;
            procRec[metalib] = fe.ParentSet.ParentLib.lib_name;
        }

        const string CELL_INFO_FORMAT = "行:【{0}】|列:【{1}】|Sheet:【{2}】|Excel:【{3}】";
        static public string MakeExcelCellInfo(Sheet sheet, int row, int column) {
            return string.Format(CELL_INFO_FORMAT, row + 1, column + 1, sheet.name, sheet.book.FilePath);
        }
        static public string MakeExcelCellInfo(string excelname, string sheet_name, int row, int column) {
            return string.Format(CELL_INFO_FORMAT, row + 1, column + 1, sheet_name, excelname);
        }

        static public void ParseFinish() {
            procRec.Clear();
        }

        
        static public void PushError(string str_format, params object[] args) {
            errList.Add(string.Format(str_format, args));
        }

        static public bool Report() {
            if(errList.Count > 0) {
                Console.WriteLine("---------错误----------");
                if(procRec.Count > 0) {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("XML解析中断于 : ");
                    foreach(var item in procRec) {
                        sb.AppendFormat("【{0}】: {1} | ", item.Key.ToString(), item.Value.ToString());
                    }
                    Console.WriteLine(sb.ToString()); 
                }
                foreach(string v in errList) {
                    Console.WriteLine(v);
                }
                Console.WriteLine("---------错误----------");
                errList.Clear();
                return false;
            }
            else {
                Console.WriteLine("处理完毕");
                return true;
            }
        }

    }
}
